package com.ccp.dev.core.basic.consts;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.access.ConfigAttribute;
import org.springframework.security.access.SecurityConfig;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.stereotype.Component;

/**
 * 常量类
 * @author ccp
 */
@Component
public class SystemConst {
    /**ISysRole const**/
	private final static String ROLE_SUPER  = "ROLE_SUPER";//超级
	private final static String ROLE_PUBLIC  = "ROLE_PUBLIC";//公共角色
	private final static String ROLE_ANONYMOUS  = "ROLE_ANONYMOUS";//匿名级
	private final static String ROLE_NONE  = "ROLE_NONE";//资源没有分配角色
	private final static String ROLE_REST  = "ROLE_REST";//用于访问rest风格的资源


	public final static GrantedAuthority ROLE_GRANT_SUPER=new SimpleGrantedAuthority(SystemConst.ROLE_SUPER);
	public final static ConfigAttribute ROLE_CONFIG_PUBLIC=new SecurityConfig(SystemConst.ROLE_PUBLIC);
	public final static ConfigAttribute ROLE_CONFIG_ANONYMOUS=new SecurityConfig(SystemConst.ROLE_ANONYMOUS);
	public final static ConfigAttribute ROLE_CONFIG_NONE=new SecurityConfig(SystemConst.ROLE_NONE);
	public final static ConfigAttribute ROLE_CONFIG_REST=new SecurityConfig(ROLE_REST);

	/**ISysOrg const**/
	private static final long serialVersionUID = 1L;
	public final static Long BEGIN_DEMID=1L;//默认维度
	public final static Long BEGIN_ORGID=1L;//默认组织ID
	public final static Integer BEGIN_DEPTH=0;//默认深度
	public final static String BEGIN_PATH="1";//默认路径
	public final static Short BEGIN_TYPE=1;//默认组织类型
	public final static Long BEGIN_ORGSUPID=-1L;//默认组织父ID
	public final static Short BEGIN_SN=1;//默认sn
	public final static Short BEGIN_FROMTYPE=0;//默认组织类型
	public final static String SUPER_ADMIN_ID  = "orgResourcesManager";//超管初始化id

	public final static String TOP_ORG_ID  = "10000006340003";//初始化数据 顶级组织id 供超管使用
	public final static  Object TOP_ORG_SUP_ID = "0";//顶级组织的orgSupId

	/**ISysUser const**/
	public final static String SEARCH_BY_ROL = "1";// 从角色
	public final static String SEARCH_BY_ORG = "2";// 从组织
	public final static String SEARCH_BY_POS = "3";// 从岗位
	public final static String SEARCH_BY_ONL = "4";// 从在线

	/**三员资源别名定义**/
	public final static String ORG_RES_MAG = "zzglyj";
	public final static String RES_MAG = "resmag";
	public final static String SYSTEM_LOG = "xtrz";
	public final static String THREENUMBER_LOG = "syrz";
	public final static String SYSTEM_PROPERTY = "sysProperty";
	public final static String SYSTEM_LOG_SWITCH = "sysLogSwitch";

	/**
	 * 默认角色
	 */
	public static final String DEFAULT_ROLE_CATEGORY = "默认角色";

	/**
	 * 数据源常量
	 */
	public static final String STR_ALL_DATASOURCE = "全部数据源_";
	/**
	 * 字符串数据源_
	 */
	public static final String STR_DATASOURCE = "数据源_";
	/**
	 * 系统数据源
	 */
	public static final String SYS_DATA_SOURCE="sysDataSource";
	/**
	 * 字符串默认值0
	 */
	public static final String DEFAULT_STR_ZERO = "0";
	
	/**
	 * 账号未锁定
	 */
	public final static Short UN_LOCKED = 0;
	/**
	 * 账号被锁定
	 */
	public final static Short LOCKED = 1;

	/**
	 * 账号未期
	 */
	public final static Short UN_EXPIRED = 0;

	/**
	 * 账号过期
	 */
	public final static Short EXPIRED = 1;

	/**
	 * 账号激活
	 */
	public final static Short STATUS_OK = 1;

	/**
	 * 账号禁用
	 */
	public final static Short STATUS_NO = 0;
	/**
	 * 账号删除
	 */
	public final static Short STATUS_Del = -1;
	/**
	 * 角色是否允许删除
	 */
	public final static Short ROLE_ALLOW_DEL = 0;
	/**
	 * 角色是否允许编辑
	 */
	public final static Short ROLE_ALLOW_EDIT = 0;
	/**
	 * 角色是否启用
	 */
	public final static Short ROLE_ENABLED = 1;
	/**
	 * 角色是否可切换
	 */
	public final static Short ROLE_ENABLEDSWITCH = 1;
	/**
	 * 角色是否公开
	 */
	public final static Short ROLE_ISPUBLIC = 0;

	/**
	 * 数据来自系统添加
	 */
	public final static Short FROMTYPE_DB=0;
	/**
	 * 数据来自AD同步,并在系统中未被设置
	 */
	public final static Short FROMTYPE_AD=1;
	/**
	 * 数据来自AD同步,并在系统中被设置过
	 */
	public final static Short FROMTYPE_AD_SET=2;
	/**
	 * 系统用户ID(任务到期时，系统自动处理任务时使用)
	 */
	public final static String SYSTEMUSERID = "";
	/**
	 * 系统用户名(任务到期时，系统自动处理任务时使用)
	 */	
	public final static String SYSTEMUSERNAME = "系统";
	/**
	 * cglib转换json为对象时，需要在json的key前面添加的前缀
	 */
	public final static String CGLIB_PREFIX = "$cglib_prop_";

	public final static String URL_END_PREFIX = ".ht";
	/**
	 * 状态 1 可用
	 */
	public final static int STATUS_Y = 1;
	/**
	 * 状态 0 不可用
	 */
	public final static int STATUS_N = 0;

	/**
	 * 资源管理 公共资源标识
	 */
	public final static short PUBLIC_Y = 1;
	/**
	 * 资源管理 非公共资源标识
	 */
	public final static short PUBLIC_N = 0;
	public final static short TENANT_IDENTIFY = 1;
	/**
	 * 默认系统id，来源与sys_res表中，系统初始化时，其它菜单的系统id，本id来源于sys_subsystem表，为系统初始化时的数据
	 */
	public static final String DEFAULT_SYSTEM_ID = "1";
	/**
	 * 默认顶级资源节点id  为0时会出现主菜单“赛博云平台”；为mainmenu时会直接显示一级菜单
	 */
	public static final String DEFAULT_TOP_SOURCE_ID = "mainmenu";
	/**
	 * 由sql脚本初始化导入 顶级资源（赛博云+开发平台）节点id
	 */
	public static final String PUBLIC_TOP_RESOURCE_ID = "mainmenu";
	/**
	 * 由sql脚本初始化导入 公共资源根节点id
	 */
	public static final String PUBLIC_RESOURCE_ROOT_ID = "ggzy";
	/**
	 * 由sql脚本初始化导入 公共资源根节点别名
	 */
	public static final String PUBLIC_RESOURCE_ROOT_ALIAS = "ggzy";
	public static final String ICON_FONT = "iconfont";
	public static final String ZTREE_ICON = "ztreeIcon";
	public static final String TENANT_CHINESE_IDENTIFY = "[租户]";
	public static final String TENANT_IMG_IDENTIFY= " <span class='iconfont iconicon_meeting'></span> ";

	public static String tenantImgIdentify;

	@Value("${tenant.img.identify}")
	public void setTenantImgIdentify(String tenantImgIdentify) {
		SystemConst.tenantImgIdentify = tenantImgIdentify;
	}

	/**
	 * 拼接json字符串的大括号前缀
	 */
	public final static String BRACE_PFEFIX_START = "{";
	public final static String BRACE_PFEFIX_END = "}";

	/**
	 * 用于通用的token参数的参数名称
	 */
	public final static String TOKEN_NAME = "token";
	public final static String USERNAME_TOKEN = "userName";
	public final static String LOCK_ID_TOKEN = "lockIp";
	public final static String CURRENT_URI_TOKEN = "currentURI";
	public static final  String JSESSIONID = ";jsessionid";//用于截取jessionid
	/**
	 * 和im模块关联表
	 */
	public static final String IM_CONNECTION_TABLE = "im_user";
}
